<?php
require_once "includes/config.php";
require_once "includes/functions.php";

$sqlExpireProduct="select * from tbl_product where expire_status='No'";
$exeExpireProduct=mysql_query($sqlExpireProduct) or die(mysql_error());
while($arrExpireProduct=mysql_fetch_array($exeExpireProduct))
{
   $arrExpireItem=mysql_fetch_array(mysql_query("select * from tbl_items where product_id='".$arrExpireProduct['product_id']."'"));
   $today=time();
   $expire_date=strtotime($arrExpireItem['bargain_duration']);
   if($today>$expire_date)
   {
	 $subject="Your Product Listing Expired";
	 $sqlEmail="select * from tbl_emails where email_type='Product Expired'";
	 $resEmail=mysql_query($sqlEmail);
	 $rowEmail=mysql_fetch_array($resEmail);
	 
	 $selCategory=mysql_fetch_array(mysql_query("select * from tbl_category where category_id='".$arrExpireItem['category_id']."'"));
	 
	 $selUser=mysql_fetch_array(mysql_query("select * from tbl_users where user_id='".$arrExpireProduct['posted_by']."'"));
	 $fullname=$selUser['first_name']." ".$selUser['last_name'];
	 
	 $message=str_replace('%fname%',$selUser['first_name'],str_replace('%lname%',$selUser['last_name'],str_replace('%post_product%',stripslashes($arrExpireProduct['product_name']),str_replace('%product_category%',stripslashes($selCategory['category_name']),$rowEmail['email_body']))));
	 $headers = "From: Swapen.com<mail@swapen.com> \r\n";
	 $headers .= 'MIME-Version: 1.0' . "\r\n";
	 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	 mail($selUser['email'],$subject, $message, $headers);
	 
	 mysql_query("update tbl_product set expire_status='Yes' where product_id='".$arrExpireProduct['product_id']."'") or die(mysql_error());
   }
}
?>



